package com.spark.market.controller;

import com.spark.market.api.dto.UserInfo;
import com.spark.market.api.utils.ResponseResult;
import com.spark.market.api.utils.ResponseUtil;
import com.spark.market.common.utils.AssertUtils;
import com.spark.market.service.UserQueryCoreService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user/query")
public class UserQueryController extends BaseController{
    @Resource
    private UserQueryCoreService userQueryCoreService;

    //获取用户详情
    @GetMapping("getInfo/{userId}")
    public ResponseResult<UserInfo> queryUserInfo(@PathVariable("userId") Integer userId){
        AssertUtils.isNotNull(userId, "userId is null");
        UserInfo userInfo = userQueryCoreService.queryUserInfo(userId);
        if (userInfo == null) return ResponseUtil.createFailedResult(null);
        return ResponseUtil.createSuccessResult(userInfo);
    }

    //获取用户opt
    @PostMapping(value = "getOtp/{telephone}")
    public ResponseResult<Object> getUserOpt(@PathVariable("telephone") String telephone){
        AssertUtils.isNotNull(telephone, "telephone is null");
        userQueryCoreService.queryOpt(telephone);
        return ResponseUtil.createSuccessResult("null","get opt success");
    }
}
